import { ScssOptions } from '../typing'
import { getLoader } from '../utils'
// 创建一个简单的PostCSS插件，用于移除所有@charset
const removeAllCharsets = () => {
    return (root) => {
        root.walkAtRules('charset', (rule) => {
            rule.remove()
        })
    }
}
export const stylePlugin = function (scssOptions?: ScssOptions) {
    if (!scssOptions) {
        return
    }
    const { plugins = [], ...rest } = { ...scssOptions }
    const styles = getLoader('rollup-plugin-styles')
    return styles({
        mode: ['extract'],
        autoModules: /\.scss$/,
        extensions: ['.css', 'scss', 'less'],
        plugins: [removeAllCharsets(), ...plugins],
        ...rest
    })
}
